<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>通讯录登录页面</title>
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/css/common.css"/>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/js/jquery.cookie.js"></script>
</head>
<body>
<div style="padding: 100px 100px 10px;">
    <h2 align="center" style="font-family: 楷体">同学录管理系统注册页面</h2>
    <form class="col-md-12" role="form" action="register-user" method="post">
        <div class="form-group input-group input-group-lg col-md-4 col-md-offset-4">
            <span class="input-group-addon">用户名</span>
            <input type="text" class="form-control" placeholder="请输入学号" name="username" id="username">
        </div>
        <br>
        <div class="form-group input-group input-group-lg col-md-4 col-md-offset-4">
            <span class="input-group-addon">邮箱账号</span>
            <input type="text" class="form-control" placeholder="请输入邮箱号码" name="email" id="toEmail">
        </div>
        <br>
        <div class="form-group input-group input-group-lg col-md-4 col-md-offset-4">
            <!---->
            <input type="text" class="form-control" placeholder="请输入邮箱中获取到的验证码" name="code" id="send-email">
            <span class="input-group-addon btn btn-success" id="sendCode">获取验证码</span>
            <!--<input type="button" class="btn btn-success"  value="点击发送验证码" onclick="sendCode(this)" />-->
        </div>
        <br>
        <div class="form-group input-group input-group-lg col-md-4 col-md-offset-4">
            <span class="input-group-addon">密码</span>
            <input type="password" class="form-control" placeholder="请输入密码" name="password">
        </div>
        <br>
        <div class="form-group input-group input-group-lg col-md-4 col-md-offset-4">
            <span class="input-group-addon">密码</span>
            <input type="password" class="form-control" placeholder="请再次输入密码" name="password1">
        </div>
        <br>
        <div class="form-group col-md-4 col-md-offset-4">
            <input type="submit" class="btn btn-success col-md-12" value="提交注册">
        </div>
        <div class="form-group col-md-4 col-md-offset-4">
            <input type="button" class="btn btn-danger col-md-12" value="返回登录页面" id="login">
        </div>
    </form>
</div>
<script>

    // $(document).ready(function(){
    //   //从cookies读取，过期时间，减去现在的时间为剩余多少秒
    // });


    $("#login").click(function () {
        location.href = "login";
    });

    var wait = 60;
    $("#sendCode").click(function () {
        if ($("#sendCode").attr("disabled") == "disabled") {
            return;
        }
        $.post("get-code", {"username": $("#username").val(), "toEmail": $("#toEmail").val()}, function (data) {
            alert(data.errMsg);
        })
    });
    $("#sendCode").click(
        function time(obj, flag) {
            if ($("#sendCode").attr("disabled") == "disabled" && flag != 1) {
                return;
            }
            if (wait == 0) {
                $("#sendCode").removeAttr("disabled");
                $("#sendCode").text("获取验证码");
                wait = 60;
            } else {
                $("#sendCode").attr("disabled", "true");
                $("#sendCode").text(wait + "秒后重试");
                wait--;
                setTimeout(function () {     //倒计时方法
                    time(obj, 1);
                }, 1000);    //间隔为1s
            }
        }
    );


</script>
</body>
</html>